package com.dongdongshop.controller;

import com.dongdongshop.admin.vo.ContentVO;
import com.dongdongshop.common.Result;
import com.dongdongshop.em.ResultEnum;
import com.dongdongshop.service.ContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("content")
public class ContentController {
    @Autowired
    private ContentService contentService;


    @PostMapping("getAllContent")
    public Result getAllContent(){
        List<ContentVO> contentVOList = contentService.getAll();
        return Result.OK().setData(contentVOList);
    }

    @PostMapping("addContentVO")
    public Result addContentVO(@RequestBody ContentVO contentVO){
        contentService.insert(contentVO);
        return Result.OK();
    }

    @PostMapping("updateContent")
    public Result updateContent(@RequestBody ContentVO conVO){
        contentService.updateContent(conVO);
        return Result.OK();
    }

    @DeleteMapping("deleteContent")
    public Result deleteContent(Long[] ids){
        contentService.deleteContent(ids);
        return Result.OK();
    }

    @PostMapping("getById")
    public Result getById(@RequestParam Long id){
        List<ContentVO> conVO = contentService.contentList(id);
        return Result.OK().setData(conVO);
    }

    //轮播图
    @PostMapping("selectByIdLunBo")
    public Result selectByIdLunBo(Long categoryId){
            List<ContentVO> contentList = contentService.selectByIdLunBo(categoryId);
            return Result.OK().setData(contentList);
    }

    //今日上新
    @PostMapping("selectByIdNew")
    public Result selectByIdNew(Long categoryId){
            List<ContentVO> contentList = contentService.selectByIdNew(categoryId);
            return Result.OK().setData(contentList);
    }

    //猜你喜欢
    @PostMapping("selectByIdLove")
    public Result selectByIdLove(Long categoryId){
        List<ContentVO> contentList = contentService.selectByIdLove(categoryId);
        return Result.OK().setData(contentList);
    }
}
